import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    name: 'Index',
    meta: {
      title: '首页'
    },
    component: () => import(/* webpackChunkName: "Index" */ '../views/index/index.vue')
  },
  {
    path: '/404',
    component: () => import('../views/404.vue'),
    hidden: true
  },
  { path:  "/:pathMatch(.*)*", redirect: '/404', hidden: true }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to,from,next) => {
  const title = to.meta && to.meta.title
  // 设置标题
  if (title) {
    document.title = title
  }

  next()

})

export default router